home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4327 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: cin.get() function challenge
  5. Date: 29 Jan 1996 19:39:51 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan29143951@g7240065.bridge.bst.bls.com>
  8. References: <4eavds$d0u@news.cencom.net>
  9. NNTP-Posting-Host: bstfirewall.bst.bls.com
  10. In-reply-to: wsenn@cencom.net's message of 26 Jan 1996 16:27:40 GMT
  11.  
  12. In article <4eavds$d0u@news.cencom.net> wsenn@cencom.net (Will Senn) writes:
  13.  
  14. : Some of you may recall my post of a week ago asking for help on getch() and
  15. : cin.  The responses I received were not encouraging.
  16.  
  17.        Write a function in C++ not using getch() that will read in ONE 
  18. : character at a time, without line buffering.  In other words when the user
  19. : presses ONE key, take and process that keypress.  I had originally asked if
  20. : it was possible to use cin or another iostream for this purpose.  It would be
  21. : nice if someone could definitively address this question.
  22.  
  23. Portably this *cannot* be done.
  24.  
  25. [snip]
  26. : If they had finished
  27. : the chapter they were reading they might have noticed that the get() member
  28. : function of cin is ALWAYS line buffered!  Another way they might have realized
  29. : that their answer was wrong would have been to COMPILE it.
  30.  
  31. cin is not ALWAYS line buffered, in fact cin is not buffered at all according
  32. to the standard:
  33.  
  34. 27.3.1 Narrow stream objects
  35.  
  36.    istream cin
  37.  
  38. 1. The object cin controls input from an unbuffered stream buffer associated
  39.    with the object stdin, declared in <cstdio>.
  40. ...
  41.  
  42. From the ANSI C std.
  43.  
  44. ... When opened, the standard input stream is fully buffered if and only if the
  45. stream can be determined not to refer to an interactive device.
  46.  
  47. It is the host environment which line buffers.  
  48. In the UNIX environment you can use ioctl() calls to change the
  49. buffering characteristics of the terminal attached to cin, in other
  50. environments there may or may not be a mechanism by which you can
  51. inform the environment that line buffering is not to be performed.
  52. This is very dependent on the host environment, try a programmers
  53. newsgroup for the environment you are interested in.
  54.  
  55. Regards
  56.  
  57.   -A.
  58. -- 
  59. | A.Champion                |
  60.